package net.hn.hnms.biz.training.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.hn.hnms.biz.training.request.AccessmentResultReq;
import net.hn.hnms.biz.training.request.AccessmentStatisticsReq;
import net.hn.hnms.biz.training.service.IAssessmentResultService;
import net.hn.hnms.biz.training.vo.AccessmentResultVO;
import net.hn.hnms.biz.training.vo.AccessmentScoreVO;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.core.domain.ResponsePage;
import net.hn.hnms.sys.common.core.web.controller.BaseController;
import net.hn.hnms.sys.common.log.annotation.Log;
import net.hn.hnms.sys.common.log.enums.BusinessType;
import net.hn.hnms.sys.common.mybatis.core.page.PageQuery;
import net.hn.hnms.sys.common.satoken.config.AutoSetMineCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author Wang Jingrui
 * @date 2022/8/24 14:28
 */
@Api(value = "考评结果模块", tags = {"考评结果"})
@RestController
@RequestMapping("/assessment")
public class AssessmentResultController extends BaseController {

    @Autowired
    private IAssessmentResultService assessmentResultService;


    /**
     * 考评结果导入
     */
    @ApiOperation("考评结果导入")
    @SaCheckPermission("training:assessment:import")
    @PostMapping("/import")
    @Log(title = "考评结果导入", businessType = BusinessType.IMPORT)
    @AutoSetMineCode
    public R<Void> importResult(@RequestParam(name = "date") Long date, @RequestPart MultipartFile file,String mineCode) {
        assessmentResultService.importResult(new Date(date),file,mineCode);
        return R.ok();
    }

    /**
     * 考评结果模板下载
     */
    @ApiOperation("考评结果模板下载")
    @SaCheckPermission("training:assessment:download")
    @GetMapping("/download")
    @Log(title = "考评结果模板下载", businessType = BusinessType.EXPORT)
    public void downloadTemplate(HttpServletResponse response) {
        assessmentResultService.downloadTemplate(response);
    }

    /**
     * 考评结果分页列表
     */
    @ApiOperation("获取考评结果分页列表")
//    @SaCheckPermission("assessment:page")
    @GetMapping("/page")
    @AutoSetMineCode
    public R<ResponsePage<AccessmentResultVO>> page(AccessmentResultReq req, PageQuery pageQuery) {
        return R.ok(assessmentResultService.selectPageList(req, pageQuery));
    }

    /**
     * 获取岗位工种  区科  考评成绩 查询下拉菜单
     */
    @ApiOperation("获取岗位工种  区科  考评成绩")
//    @SaCheckPermission("assessment:dict")
    @GetMapping("/dict")
    @AutoSetMineCode
    public R<Map<String, Set<String>>> dict(@ApiParam(value = "煤矿编码") String mineCode) {
        return R.ok(assessmentResultService.dict( mineCode));
    }

    /**
     * 考评分段人数占比饼图
     */
    @ApiOperation("考评分段人数占比饼图")
//    @SaCheckPermission("access:statistics:pie")
    @GetMapping("/pie")
    @AutoSetMineCode
    public R<List<Map<String, Object>>> pieChart(AccessmentStatisticsReq req) {
        return R.ok(assessmentResultService.pieChart(req));
    }

    /**
     * 考评分段人数统计折线图
     */
    @ApiOperation("考评分段人数统计折线图")
//    @SaCheckPermission("access:statistics:line")
    @GetMapping("/line")
    @AutoSetMineCode
    public R<List<AccessmentScoreVO>> lineChart(AccessmentStatisticsReq req) {
        return R.ok(assessmentResultService.lineChart(req));
    }

    /**
     * 考评分段人数统计柱状图
     */
    @ApiOperation("考评分段人数统计柱状图")
//    @SaCheckPermission("access:statistics:column")
    @GetMapping("/column")
    @AutoSetMineCode
    public R<List<List<Object>>> columnChart(AccessmentStatisticsReq req) {
        return R.ok(assessmentResultService.columnChart(req));
    }
}
